package com.tekj.cxqcb.view.Module.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;
import com.tekj.cxqcb.MainBActivity;
import com.tekj.cxqcb.R;
import com.tekj.cxqcb.operation.resultBean.SelectExpandDetailBean;
import com.tekj.cxqcb.view.Module.activity.RelatedChannelsActivity;

import java.util.List;

import common.tool.Tools;
import common.widget.CircleTransform;

/**
 * 下级列表
 */
public class RelatedChannelsAdapter extends BaseQuickAdapter<SelectExpandDetailBean.DataBean.ListBean, BaseViewHolder> {


    public RelatedChannelsAdapter(@Nullable List<SelectExpandDetailBean.DataBean.ListBean> data) {
        super(R.layout.item_related_channels, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SelectExpandDetailBean.DataBean.ListBean item) {


        helper.setText(R.id.item_tv_time, item.getCreateTime());

        helper.setText(R.id.item_tv_name, item.getName());

//        helper.setText(R.id.item_tv_phone, item.getPhone());
        String identity = "";
//        3信审员4城市合伙人5-6运管中心7-8省分公
        if (item.getRole().equals("3")) {
            identity = "信审员";
        } else if (item.getRole().equals("4")) {
            identity = "城市合伙人";
            RelatedChannelsActivity.setTextColorBG(mContext, (TextView) helper.getView(R.id.item_tv_identity), 2);
        } else if (item.getRole().equals("5") || item.getRole().equals("6")) {
            identity = "运管中心";
            RelatedChannelsActivity.setTextColorBG(mContext, (TextView) helper.getView(R.id.item_tv_identity), 1);
        } else if (item.getRole().equals("7") || item.getRole().equals("8")) {
            identity = "省分公司";
            RelatedChannelsActivity.setTextColorBG(mContext, (TextView) helper.getView(R.id.item_tv_identity), 3);
        }
        helper.setText(R.id.item_tv_identity, identity);

        helper.setText(R.id.item_tv_region, item.getAddress());

        String numString = "累计完成售车订单" + item.getSalesCarAll() + "单";

        helper.setText(R.id.tv_buy_car_num,
                Tools.setTextColor(mContext, numString, R.color.colorPrimary, numString.indexOf("单") + 1, numString.length() - 1));

        helper.addOnClickListener(R.id.tv_phone);

        Picasso.get()
                .load(item.getHead().equals("") ? "1" : item.getHead())
                .transform(new CircleTransform())
                .error(R.mipmap.icon_head)
                .placeholder(R.mipmap.icon_head)
                .into((ImageView) helper.getView(R.id.img_head));
    }
}
